<?php
/* -----------------------------------------------------------------
* 	ID:						$Id: new_products.php 2 2011-02-17 13:35:25Z akausch $
* 	Letzter Stand:			$Revision: 2 $
* 	zuletzt geändert von: 	$Author: akausch $
* 	Datum:					$Date: 2011-02-17 14:35:25 +0100 (Do, 17. Feb 2011) $
*
* 	commerce:SEO by Webdesign Erfurt
* 	http://www.commerce-seo.de
*
* 	Copyright (c) since 2010 commerce:SEO
* ------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* --------------------------------------------------------------- */

$module_smarty = new Smarty;

if ($mobile_template == 'False') {
	$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
} else {
	$module_smarty->assign('tpl_path', 'templates/'.CURRENT_MOBILE_TEMPLATE.'/');
}
$fsk_lock = '';
if ($_SESSION['customers_status']['customers_fsk18_display'] == '0')
	$fsk_lock = ' and p.products_fsk18!=1';
	
if (GROUP_CHECK == 'true')
	$group_check = " and p.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
		
if ((!isset ($new_products_category_id)) || ($new_products_category_id == '0')) {
	$site = 'new_products_default';
	$title = NEW_PRODUCTS_DEFAULT;
	
	$new_products_query = "SELECT 
								p.*,
								pd.products_name, 
								pd.products_description,  
								pd.products_short_description
							FROM
								".TABLE_PRODUCTS." p
								LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON(p.products_id = pd.products_id AND pd.language_id = '".(int) $_SESSION['languages_id']."')
							WHERE
								p.products_status = '1' 
							AND
								p.products_startpage = '1'
								".$group_check."
								".$fsk_lock."
							ORDER BY 
								p.products_startpage_sort ASC 
							LIMIT ".MAX_DISPLAY_NEW_PRODUCTS;
} else {
	$site = 'new_products';
	$title = NEW_PRODUCTS;

	if (MAX_DISPLAY_NEW_PRODUCTS_DAYS != '0') {
		$date_new_products = date("Y.m.d", mktime(1, 1, 1, date(m), date(d) - MAX_DISPLAY_NEW_PRODUCTS_DAYS, date(Y)));
		$days = " AND p.products_date_added > '".$date_new_products."' ";
	}
	$new_products_query = "SELECT 
								p.*, 
								pd.products_name, 
								pd.products_description,  
								pd.products_short_description, 
								p2c.*, 
								c.*
							FROM
								".TABLE_PRODUCTS." p 
								LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." pd ON (p.products_id = pd.products_id )
								LEFT OUTER JOIN ".TABLE_PRODUCTS_TO_CATEGORIES." p2c ON (p.products_id = p2c.products_id)
								LEFT OUTER JOIN ".TABLE_CATEGORIES." c ON (p2c.categories_id = c.categories_id)
							WHERE 
								c.categories_status='1'
							AND
							pd.language_id = '".(int) $_SESSION['languages_id']."'
								".$group_check."
								".$days."
								".$fsk_lock."
							AND 
								c.parent_id = '".$new_products_category_id."'
							AND 
								p.products_status = '1' 
							ORDER BY 
								p.products_date_added DESC 
							LIMIT 
								".MAX_DISPLAY_NEW_PRODUCTS;
}
$row = 0;
$module_content = array ();
$new_products_query = xtDBquery($new_products_query);
while ($new_products = xtc_db_fetch_array($new_products_query, true)) { 
	$row++;
	$module_content[] = $product->buildDataArray($new_products,'thumbnail',$site,$row);
}

if (sizeof($module_content) >= 1) {
	$module_smarty->assign('language', $_SESSION['language']);
	$module_smarty->assign('module_content', $module_content);
	$module_smarty->assign('TITLE', $title);
	$module_smarty->assign('CLASS', $site);

	 if (!CacheCheck()) {
		$module_smarty->caching = 0;
		if (DISPLAY_NEW_PRODUCTS_SLIDE=='true') {
			if ($mobile_template == 'False') {
				$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/new_products_default.html');
			} else {
				$module = $module_smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/new_products_default.html');
			}
		} else {
			if ($mobile_template == 'False') {
				$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/product_listings.html');
			} else {
				$module = $module_smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/product_listings.html');
			}
		}

	} else {
		$module_smarty->caching = 1;
		$module_smarty->cache_lifetime = CACHE_LIFETIME;
		$module_smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $new_products_category_id.$_SESSION['language'].$_SESSION['customers_status']['customers_status_name'].$_SESSION['currency'];
		if (DISPLAY_NEW_PRODUCTS_SLIDE=='true') {
			if ($mobile_template == 'False') {
				$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/new_products_default.html', $cache_id);
			} else {
				$module = $module_smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/new_products_default.html', $cache_id);
			}
			
		} else {
			if ($mobile_template == 'False') {
				$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/product_listings.html', $cache_id);
			} else {
				$module = $module_smarty->fetch(CURRENT_MOBILE_TEMPLATE.'/module/product_listings.html', $cache_id);
			}
		}
	}
	$default_smarty->assign('MODULE_new_products', $module);
}
?>